package com.example.springbootsfzy.controller.gengminghui;

import com.example.springbootsfzy.domain.CourseQuestions;
import com.example.springbootsfzy.service.gengminghui.CourseQuestionsService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseQuestions")
public class CourseQuestionsController {
    @Autowired
    private CourseQuestionsService courseQuestionsService;

    //查询所有问题以及咨询师昵称及答案
    @GetMapping("/selectAll")
    public R selectAll() {
        List<CourseQuestions> courseQuestions = courseQuestionsService.selectAll();
        return R.ok(courseQuestions);
    }
    //添加问题
    @PostMapping("/insert")
    public R insert(@RequestBody CourseQuestions courseQuestions) {
       int i=courseQuestionsService.insert(courseQuestions);
      if (i>0) {
          return R.ok("添加成功");
      } else {
          return R.error("添加失败");
      }
    }

    //根据id删除问题
    @DeleteMapping("/deleteById")
    public R deleteByPrimaryKey(Integer id) {
        int i=courseQuestionsService.deleteByPrimaryKey(id);
        if (i>0) {
            return R.ok("删除成功");
        } else {
            return R.error("删除失败");
        }
    }
    //根据id修改问题
    @PutMapping("/updateById")
    public R updateByPrimaryKeySelective(@RequestBody CourseQuestions courseQuestions) {
        int i=courseQuestionsService.updateByPrimaryKeySelective(courseQuestions);
        if (i>0) {
            return R.ok("修改成功");
        } else {
            return R.error("修改失败");
        }
    }
    //通过id查找问题
    @GetMapping("/selectById")
    public R selectByPrimaryKey(Integer id) {
        List<CourseQuestions> courseQuestions = courseQuestionsService.selectByCourseId(id);
        System.out.println(id);
        return R.ok(courseQuestions);
    }

    //根据咨询师id查询问题
    @GetMapping("/selectByConsultantId")
    public R selectByConsultantId(Integer id) {
        List<CourseQuestions> courseQuestions = courseQuestionsService.selectByConsultantId(id);
        return R.ok(courseQuestions);
    }



}
